package com.leyou.order.task;

import com.leyou.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author 虎哥
 */
@Component
public class EvictOrderTask {

    @Autowired
    private OrderService orderService;

    private static final long FIXED_DELAY = 600000;
    private static final long ORDER_TIME_OUT = 3600000;

    @Scheduled(fixedDelay = FIXED_DELAY)
    public void evictUnpayOrder(){
        // 计算已经超时的订单的具体时间
        Date deadLine = new Date(System.currentTimeMillis() - ORDER_TIME_OUT);
        orderService.evictUnpaidOrder(deadLine);
    }
}
